
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Dubbo学习指南 - 交互式测验</title>
      <style>
        @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');
        
        body {
          font-family: 'Noto Sans SC', sans-serif;
          background-color: #f4f7f9;
          color: #333;
          display: flex;
          justify-content: center;
          align-items: center;
          min-height: 100vh;
          margin: 0;
          padding: 20px;
          box-sizing: border-box;
        }
        
        .main-wrapper {
            position: relative;
            width: 100%;
            max-width: 900px; /* Wider to accommodate buttons */
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .quiz-container {
          background-color: #ffffff;
          border-radius: 16px;
          box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
          width: 100%;
          max-width: 700px;
          overflow: hidden;
          z-index: 10;
        }

        .quiz-header {
          background-color: #4a90e2;
          color: white;
          padding: 20px 30px;
          text-align: center;
        }

        .quiz-header h1 {
          margin: 0;
          font-size: 24px;
          font-weight: 700;
        }
        
        .quiz-header p {
            margin: 5px 0 0;
            font-size: 14px;
            opacity: 0.9;
        }

        .quiz-body {
          padding: 30px;
        }

        .progress-bar {
            display: none; /* 隐藏进度条 */
            width: 100%;
            background-color: #e0e0e0;
            border-radius: 5px;
            height: 10px;
            margin-bottom: 20px;
        }

        #progress-indicator {
            height: 100%;
            width: 0%;
            background-color: #4caf50;
            border-radius: 5px;
            transition: width 0.3s ease;
        }

        #question-container {
          margin-bottom: 20px;
        }

        #question-text {
          font-size: 18px;
          font-weight: 500;
          line-height: 1.6;
          margin-bottom: 25px;
        }

        .options-list {
          list-style: none;
          padding: 0;
          margin: 0;
        }

        .option-item {
          background-color: #f8f9fa;
          border: 1px solid #dee2e6;
          border-radius: 8px;
          padding: 15px;
          margin-bottom: 12px;
          cursor: pointer;
          transition: background-color 0.2s ease, border-color 0.2s ease;
        }

        .option-item:hover {
          background-color: #e9ecef;
        }
        
        .option-item.selected {
            background-color: #d1e7fd;
            border-color: #4a90e2;
        }

        .quiz-footer {
          padding: 20px 30px;
          display: flex;
          justify-content: space-between; /* 将按钮分布在两侧 */
          align-items: center;
          min-height: 65px; /* Reserve space */
        }

        .nav-btn {
          background-color: #4a90e2;
          color: white;
          border: none;
          border-radius: 8px;
          padding: 10px 20px;
          font-size: 16px;
          font-weight: 500;
          cursor: pointer;
          transition: background-color 0.2s ease, transform 0.2s ease;
          box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        }
        
        #next-btn {
            background-color: #28a745;
        }

        .nav-btn:hover {
          background-color: #357abd;
          transform: scale(1.05);
        }
        
        .nav-btn:disabled {
            background-color: #a0c3e8;
            cursor: not-allowed;
            opacity: 0.7;
        }

        #result-container {
            border-top: 1px solid #eee;
        }
        
        .result-box {
            border-radius: 8px;
            padding: 20px;
            margin-top: 20px;
        }
        
        .result-box.correct {
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            color: #155724;
        }

        .result-box.incorrect {
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            color: #721c24;
        }
        
        .result-box h3 {
            margin-top: 0;
        }

        .explanation-text {
            margin-top: 15px;
            line-height: 1.7;
        }
        
        .source-text {
            font-style: italic;
            font-size: 14px;
            margin-top: 15px;
            color: #555;
        }

        
        .final-score-container {
            padding: 40px;
            text-align: center;
        }
        .final-score-container h2 {
            margin-top: 0;
            margin-bottom: 30px;
        }
        .score-summary {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin-bottom: 40px;
            flex-wrap: wrap;
        }
        .score-card {
            background-color: #f8f9fa;
            border-radius: 12px;
            padding: 20px;
            width: 180px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.05);
            border: 1px solid #e9ecef;
        }
        .score-card h3 {
            margin: 0 0 10px;
            font-size: 16px;
            font-weight: 500;
            color: #555;
        }
        .score-card p {
            margin: 0;
            font-size: 28px;
            font-weight: 700;
            color: #333;
        }
        .score-details table {
            width: 100%;
            font-size: 16px;
        }
        .score-details td {
            padding: 4px 0;
        }
        .score-details td:last-child {
            text-align: right;
            font-weight: 700;
        }
        .report-actions button {
            background-color: #fff;
            border: 1px solid #ccc;
            border-radius: 8px;
            padding: 12px 25px;
            font-size: 16px;
            cursor: pointer;
            margin: 0 10px;
            transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
        }
        .report-actions button:hover {
            background-color: #f1f1f1;
            border-color: #bbb;
            transform: translateY(-2px);
        }
        .report-actions button.primary {
            background-color: #28a745;
            color: white;
            border-color: #28a745;
        }
        .report-actions button.primary:hover {
            background-color: #218838;
        }
        
        .hint-container {
            background-color: #e0f7fa;
            border: 1px solid #b2ebf2;
            border-radius: 8px;
            padding: 15px;
            margin-top: 20px;
            color: #006064;
            font-size: 15px;
            line-height: 1.6;
            display: none; /* 默认隐藏 */
        }
      </style>
    </head>
    <body>
      <div class="main-wrapper">
          <div class="quiz-container">
            <div class="quiz-header">
              <h1>Dubbo学习指南 - 交互式测验</h1>
              <p>检验你对文档内容的理解程度</p>
            </div>
            <div id="quiz-content">
                <div class="quiz-body">
                    <div class="progress-bar">
                        <div id="progress-indicator"></div>
                    </div>
                    <div id="question-container">
                      <p id="question-text"></p>
                      <ul class="options-list" id="options-list"></ul>
                    </div>
                    <div id="result-container"></div>
                    <div id="hint-container" class="hint-container"></div>
                </div>
                <div class="quiz-footer" id="quiz-footer">
                  <button id="prev-btn" class="nav-btn">上一题</button>
                  <button id="hint-btn" class="nav-btn" style="background-color: #ffc107; color: #333; box-shadow: 0 4px 12px rgba(255,193,7,0.3);">提示</button>
                  <button id="next-btn" class="nav-btn">下一题</button>
                </div>
            </div>
          </div>
      </div>

      <script>
        const quizData = [
  {
    "question": "根据文档的定义，\"分布式\"和\"集群\"这两种架构模式最本质的区别是什么？",
    "options": [
      "分布式侧重于数据备份，而集群侧重于业务拆分。",
      "分布式是多个服务单元协作完成一个复杂的业务（做不同的事），而集群是多个相同的服务单元共同承担流量（做同样的事）。",
      "分布式是为了实现高可用性，而集群是为了实现松耦合。",
      "分布式是将所有功能部署在同一台服务器上，而集群是将它们分散到多台服务器上。"
    ],
    "correctAnswerIndex": 1,
    "explanation": "文档中通过“厨师与配菜师”的例子生动地解释了两者的区别。多个厨师做同样的菜，这是集群，旨在提高处理能力和可用性。而厨师和配菜师分工合作，完成炒菜这个完整的业务，这就是分布式，旨在实现业务解耦和专业化。因此，核心区别在于各单元是“做同样的事”还是“做不同的事”。",
    "source": "文档中「1.2 分布式/集群架构」及「1.2.1 举例说明分布式和集群的概念」部分",
    "hint": "回想一下文档中的关键总结：“集群：多个人在一起作同样的事。分布式：多个人在一起作不同的事。”"
  },
  {
    "question": "在Dubbo的架构图中，哪个组件扮演着“服务通讯录”的角色，负责服务的注册与发现？",
    "options": [
      "Provider (服务提供方)",
      "Monitor (监控中心)",
      "Registry (注册中心)",
      "Consumer (服务消费方)"
    ],
    "correctAnswerIndex": 2,
    "explanation": "Registry (注册中心) 是Dubbo架构的核心，它负责管理所有服务提供者（Provider）的地址信息。Provider启动时向Registry注册自己的服务，Consumer启动时向Registry订阅自己需要的服务，从而实现服务的动态发现和调用，避免了硬编码地址。",
    "source": "文档中「2.2 Dubbo架构图」的“节点角色说明”部分",
    "hint": "服务提供者和服务消费者都需要一个共同的“中间人”来知晓对方的存在和位置。"
  },
  {
    "question": "根据Dubbo的调用流程，服务消费者(Consumer)在启动后是如何找到并调用服务提供者(Provider)的？",
    "options": [
      "Consumer直接通过硬编码的IP地址列表连接到Provider。",
      "Consumer向注册中心(Registry)订阅服务，注册中心返回Provider的地址列表，然后Consumer基于负载均衡算法选择一个进行调用。",
      "Consumer向监控中心(Monitor)查询可用的Provider地址，并进行调用。",
      "Provider启动时会主动广播自己的地址，所有网络内的Consumer都能接收到并建立连接。"
    ],
    "correctAnswerIndex": 1,
    "explanation": "文档的“调用关系说明”清晰地描述了这个过程：1. Provider向Registry注册。2. Consumer向Registry订阅。3. Registry将Provider地址列表返回给Consumer。4. Consumer通过软负载均衡算法选择一个Provider进行调用。这个机制是Dubbo实现服务自动发现和负载均衡的关键。",
    "source": "文档中「2.2 Dubbo架构图」的“调用关系说明”部分",
    "hint": "关注文档中描述的调用关系步骤2、3、4，它揭示了服务发现和选择的完整过程。"
  },
  {
    "question": "在Spring Boot整合Dubbo的实践中，服务消费者端使用`@Reference`注解的核心作用是什么？",
    "options": [
      "将一个本地Java类发布为远程Dubbo服务。",
      "声明一个对远程Dubbo服务的依赖注入引用，使得可以像调用本地方法一样调用它。",
      "用于配置Dubbo的注册中心地址和端口。",
      "激活Dubbo的监控中心，开始收集调用数据。"
    ],
    "correctAnswerIndex": 1,
    "explanation": "在服务消费方的代码中，`@Reference`注解用于声明一个远程服务的引用。Dubbo框架会自动为这个引用创建一个代理对象，屏蔽了底层的网络通信细节。这样，开发者就可以像调用一个本地接口一样，透明地调用远程服务。",
    "source": "文档中「5.3.1 Controller中调用」部分",
    "hint": "在消费者代码中，你需要一种方式来“引用”或“指向”那个远端的服务接口。"
  },
  {
    "question": "文档中提到了多种Dubbo负载均衡策略，哪一种策略的设计目标是“让响应慢的提供者接收到更少的请求”？",
    "options": [
      "轮询模式 (Round Robin)",
      "随机模式 (Random)",
      "一致性哈希 (Consistent Hash)",
      "最少活跃调用数 (Least Active)"
    ],
    "correctAnswerIndex": 3,
    "explanation": "“最少活跃调用数”策略会根据每个服务提供者当前的活跃请求数（即正在处理的请求数）来分配新请求。响应慢的提供者，其请求处理时间长，活跃数会相对较高，因此新请求会更倾向于被分配给活跃数低的（即响应更快的）提供者，从而实现动态的、基于性能的负载均衡。",
    "source": "文档中「2 Dubbo负载均衡策略」部分",
    "hint": "这种策略的核心思想是评估每个服务节点的实时“忙碌”程度。"
  },
  {
    "question": "在服务提供者（Provider）的实现类上，应该使用哪个注解来将其正确地发布（暴露）为一个Dubbo服务？",
    "options": [
      "@Reference",
      "@com.alibaba.dubbo.config.annotation.Service",
      "@DubboComponentScan",
      "@Controller"
    ],
    "correctAnswerIndex": 1,
    "explanation": "文档中的代码示例明确指出，在服务实现类（如`UserServieImpl`）上使用`@com.alibaba.dubbo.config.annotation.Service`注解，才能将其作为一个Dubbo服务发布出去，供消费者发现和调用。`@Reference`用于消费方，而`@Service`用于提供方。",
    "source": "文档中「5.2.2 服务实现类」部分",
    "hint": "提供方需要“提供服务”，消费方需要“引用服务”，请选择与“提供”相关的注解。"
  },
  {
    "question": "在服务消费者的配置文件中，设置`dubbo.consumer.check=false`会产生什么效果？",
    "options": [
      "消费者将不再检查与注册中心的连接状态。",
      "消费者在调用服务时，会跳过对提供者返回结果的检查。",
      "消费者应用在启动时，即使它所依赖的服务提供者不存在，也不会报错退出。",
      "关闭消费者的重试机制，即`dubbo.consumer.retries`将失效。"
    ],
    "correctAnswerIndex": 2,
    "explanation": "默认情况下，Dubbo消费者在启动时会检查其所依赖的远程服务是否可用，如果找不到提供者，启动会失败。将`dubbo.consumer.check`设置为`false`可以关闭这个启动时检查，允许消费者应用先行启动。这在开发调试或某些复杂的部署顺序中非常有用。",
    "source": "文档中「5.3.1 服务消费者配置」部分",
    "hint": "这个配置项与消费者应用的“启动过程”有关。"
  },
  {
    "question": "根据文档的总结，从单体架构演进到分布式架构，主要为了达到以下哪三个核心目标？",
    "options": [
      "高可用、高并发、松耦合",
      "降低成本、简化运维、代码复用",
      "数据一致性、事务完整性、快速开发",
      "统一协议、集中管理、减少服务器数量"
    ],
    "correctAnswerIndex": 0,
    "explanation": "文档的「1.4 总结」部分明确指出，分布式架构演进的核心驱动力是为了解决单体架构的不足，主要目标是：1. 高可用（通过冗余和故障转移避免单点失败）；2. 高并发（通过水平扩展分散请求压力）；3. 松耦合（通过服务拆分使各模块独立开发、部署和扩展）。",
    "source": "文档中「1.4 总结」部分",
    "hint": "在文档的开头部分，有一个专门的章节总结了架构演进的目的。"
  }
];
        console.log("Quiz Data:", JSON.parse(JSON.stringify(quizData))); // 添加这行用于调试，以可展开的JSON格式输出
        
        let currentQuestionIndex = 0;
        let score = 0;
        // 存储每个问题的回答状态
        const userAnswers = new Array(quizData.length).fill(null); 

        const questionTextEl = document.getElementById('question-text');
        const optionsListEl = document.getElementById('options-list');
        const resultContainerEl = document.getElementById('result-container');
        const quizContentEl = document.getElementById('quiz-content');
        const progressIndicatorEl = document.getElementById('progress-indicator');
        const prevBtn = document.getElementById('prev-btn');
        const nextBtn = document.getElementById('next-btn');
        const hintBtn = document.getElementById('hint-btn');
        const hintContainerEl = document.getElementById('hint-container');

        function loadQuestion() {
          resultContainerEl.innerHTML = '';
          optionsListEl.innerHTML = '';
          hintContainerEl.style.display = 'none'; // 隐藏提示
          
          if (currentQuestionIndex >= quizData.length) {
            showFinalScore();
            return;
          }

          updateProgress();

          const currentQuestion = quizData[currentQuestionIndex];
          questionTextEl.textContent = `(${currentQuestionIndex + 1}/${quizData.length}) ${currentQuestion.question}`;
          
          currentQuestion.options.forEach((optionText, index) => {
            const li = document.createElement('li');
            li.className = 'option-item';
            li.textContent = optionText;
            li.dataset.index = index; // Store index in a data attribute
            // 如果这道题已经回答过，恢复状态
            if (userAnswers[currentQuestionIndex] !== null) {
                if (index === userAnswers[currentQuestionIndex]) {
                    li.classList.add('selected');
                }
            }
            optionsListEl.appendChild(li);
          });

          // 如果已经回答过，直接显示结果
          if (userAnswers[currentQuestionIndex] !== null) {
              const isCorrect = userAnswers[currentQuestionIndex] === currentQuestion.correctAnswerIndex;
              showResult(isCorrect, currentQuestion);
          }
          
          updateNavigationButtons();
          updateProgress();
        }

        function selectOption(optionIndex) {
            userAnswers[currentQuestionIndex] = optionIndex;
            const currentQuestion = quizData[currentQuestionIndex];
            const isCorrect = optionIndex === currentQuestion.correctAnswerIndex;

            // 重新计算分数
            score = userAnswers.reduce((acc, answer, index) => {
                return answer === quizData[index].correctAnswerIndex ? acc + 1 : acc;
            }, 0);

            showResult(isCorrect, currentQuestion);
            updateNavigationButtons();
        }
        
        function updateProgress() {
            const answeredQuestions = userAnswers.filter(answer => answer !== null).length;
            const progressPercentage = (answeredQuestions / quizData.length) * 100;
            progressIndicatorEl.style.width = `${progressPercentage}%`;
        }
        
        function updateNavigationButtons() {
            prevBtn.style.display = 'block';
            nextBtn.style.display = 'block';
            hintBtn.style.display = 'block'; // 显示提示按钮

            prevBtn.disabled = currentQuestionIndex === 0;
            nextBtn.disabled = false; // 最后一题时，下一题按钮不禁用，而是用于显示报告
            nextBtn.textContent = (currentQuestionIndex === quizData.length - 1) ? '查看报告' : '下一题';
            
            // 如果当前问题没有提示，则禁用提示按钮并隐藏提示内容
            if (!quizData[currentQuestionIndex].hint) {
                hintBtn.disabled = true;
                hintContainerEl.style.display = 'none';
                hintContainerEl.textContent = ''; // 清除旧的提示内容
            } else {
                hintBtn.disabled = false;
            }
        }

        function showResult(isCorrect, questionData) {
            resultContainerEl.innerHTML = ''; // 清空之前的结果
            const resultBox = document.createElement('div');
            resultBox.className = `result-box ${isCorrect ? 'correct' : 'incorrect'}`;
            
            let html = `<h3>${isCorrect ? '回答正确！' : '回答错误'}</h3>`;
            if (!isCorrect) {
                html += `<p><strong>正确答案是：</strong> ${questionData.options[questionData.correctAnswerIndex]}</p>`;
            }
            html += `<div class="explanation-text">${questionData.explanation}</div>`;
            html += `<div class="source-text">来源: ${questionData.source}</div>`;
            
            resultBox.innerHTML = html;
            resultContainerEl.appendChild(resultBox);

            // 禁用所有选项的点击事件，并高亮正确/错误答案
            Array.from(optionsListEl.children).forEach((child, index) => {
                child.style.pointerEvents = 'none';
                // 高亮正确答案
                if (index === questionData.correctAnswerIndex) {
                    child.classList.add('correct'); // 需要添加CSS样式
                    child.style.backgroundColor = '#d4edda';
                    child.style.borderColor = '#c3e6cb';
                }
                // 如果选错了，高亮错误选项
                if (!isCorrect && index === userAnswers[currentQuestionIndex]) {
                    child.classList.add('incorrect'); // 需要添加CSS样式
                    child.style.backgroundColor = '#f8d7da';
                    child.style.borderColor = '#f5c6cb';
                }
            });
        }

        function goToNextQuestion() {
            if (currentQuestionIndex < quizData.length - 1) {
                currentQuestionIndex++;
                loadQuestion();
            } else {
                showFinalScore();
            }
        }

        function goToPreviousQuestion() {
            if (currentQuestionIndex > 0) {
                currentQuestionIndex--;
                loadQuestion();
            }
        }
        
        function showHint() {
            const currentQuestion = quizData[currentQuestionIndex];
            if (currentQuestion.hint) {
                hintContainerEl.textContent = currentQuestion.hint;
                hintContainerEl.style.display = 'block';
            } else {
                hintContainerEl.style.display = 'none';
            }
        }

        function showFinalScore() {
            document.querySelector('.quiz-body').style.display = 'none';
            document.getElementById('quiz-footer').style.display = 'none';

            const correctCount = score;
            const totalQuestions = quizData.length;
            const answeredCount = userAnswers.filter(a => a !== null).length;
            const wrongCount = answeredCount - correctCount;
            const skippedCount = totalQuestions - answeredCount;
            const accuracy = totalQuestions > 0 ? Math.round((correctCount / totalQuestions) * 100) : 0;
            const errorRate = totalQuestions > 0 ? Math.round((wrongCount / totalQuestions) * 100) : 0;

            const finalScoreHtml =
                '<div class="final-score-container">' +
                '<h2>答题报告</h2>' +
                '<div class="score-summary">' +
                '<div class="score-card">' +
                '<h3>得分</h3>' +
                '<p>' + correctCount + ' / ' + totalQuestions + '</p>' +
                '</div>' +
                '<div class="score-card">' +
                '<h3>正确率</h3>' +
                '<p>' + accuracy + '%</p>' +
                '</div>' +
                '<div class="score-card">' +
                '<h3>错误率</h3>' +
                '<p>' + errorRate + '%</p>' +
                '</div>' +
                '<div class="score-card score-details">' +
                '<table>' +
                '<tr><td>正确</td><td>' + correctCount + '</td></tr>' +
                '<tr><td>错误</td><td>' + wrongCount + '</td></tr>' +
                '<tr><td>未答</td><td>' + skippedCount + '</td></tr>' +
                '</table>' +
                '</div>' +
                '</div>' +
                '<div class="report-actions">' +
                '<button id="review-btn">回顾测验</button>' +
                '<button class="primary" onclick="location.reload()">再试一次</button>' +
                '</div>' +
                '</div>';

            let reportEl = document.querySelector('.final-score-container');
            if (reportEl) {
                reportEl.remove();
            }
            quizContentEl.insertAdjacentHTML('beforeend', finalScoreHtml);
            document.getElementById('review-btn').addEventListener('click', reviewQuiz);
        }

        function reviewQuiz() {
            const reportEl = document.querySelector('.final-score-container');
            if (reportEl) {
                reportEl.remove();
            }

            document.querySelector('.quiz-body').style.display = 'block';
            document.getElementById('quiz-footer').style.display = 'flex';
            
            currentQuestionIndex = 0;
            loadQuestion();
            updateNavigationButtons(); // Ensure nav buttons are correctly displayed
        }

        // Event Delegation for options
        optionsListEl.addEventListener('click', (event) => {
            if (event.target && event.target.matches('li.option-item')) {
                // Check if the question has already been answered
                if (userAnswers[currentQuestionIndex] === null) {
                    const selectedIndex = parseInt(event.target.dataset.index, 10);
                    selectOption(selectedIndex);
                }
            }
        });

        prevBtn.addEventListener('click', goToPreviousQuestion);
        nextBtn.addEventListener('click', goToNextQuestion);
        hintBtn.addEventListener('click', showHint);
        
        // 初始加载
        loadQuestion();
      </script>
    </body>
    </html>
  